package entities.role;

import java.util.HashSet;

import entities.concept.AndConcept;
import entities.concept.Concept;

/**
 * Only simple roles are considered at the moment
 * Can be extended to allow role inclusions, paths, etc.
 * @author j55wu
 *
 */
public class Role{

	private final String rolename;
	private Concept domain=null, range=null;
	
	public Role(String name){
		this.rolename = name;
	}
	
	public String getRoleName(){
		return this.rolename;
	}
	
	public void setDomain(Concept dm){
		if(domain == null){
			this.domain = dm;
		}else{
			//conjunction of new domain
			HashSet<Concept> cons = new HashSet<Concept> ();
			cons.add(this.domain);
			cons.add(dm);
			this.domain = new AndConcept(cons);
		}
	}
	
	
	public void setRange(Concept rg){
		if(this.range == null){
			this.range = rg;
		}else{
			//conjunction of new range
			HashSet<Concept> cons = new HashSet<Concept> ();
			cons.add(this.range);
			cons.add(rg);
			this.range = new AndConcept(cons);
		}
	}
	
	public Concept getDomain(){
		return this.domain;
	}
	
	public Concept getRange(){
		return this.range;
	}

	@Override
	public int hashCode() {
		final int prime = 257;
		int result = 1;
		result = prime * result
				+ ((rolename == null) ? 0 : rolename.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof Role))
			return false;
		Role other = (Role) obj;
		if (rolename == null) {
			if (other.rolename != null)
				return false;
		} else if (!rolename.equals(other.rolename))
			return false;
		return true;
	}
	
	public Role getPrimeCopy() {
		return new Role(this.rolename + Concept.PRIME);
	}
	
	@Override
	public String toString() {
		return rolename;
	}
}
